package csel.model.entity;

import csel.model.Direction;
import csel.model.entity.Character;

public class AngryAi extends ArtificialIntelligence
{
	/**
	 * Change this if we change its structure.
	 */
	private static final long serialVersionUID = 5L;

	private Character angryAt;
	private NonPlayerCharacter self;
	private Direction wantToMove;
	private int ticksToAttack;
	private int ticksTillThink;

	public AngryAi(Character c, NonPlayerCharacter self)
	{
		angryAt = c;
		this.self = self;
		ticksToAttack = 50;
		ticksTillThink = 10;
	}
	public void tick()
	{
		ticksToAttack--;
		ticksTillThink--;
		if(ticksToAttack <= 0)
		{
			self.attack();
			ticksToAttack = 50;
		}
		if(ticksTillThink <= 0)
		{
			thinkAngryThoughts();
			ticksTillThink = 10;
		}
	}
	private void thinkAngryThoughts()
	{
		int pissedX = angryAt.getTile().getLocation().getX();
		int pissedY = angryAt.getTile().getLocation().getY();

		int myX = self.getTile().getLocation().getX();
		int myY = self.getTile().getLocation().getY();

		if((Math.abs(myX-pissedX) > 10) || (Math.abs(myY-pissedY) > 10))
		{
			self.stop();
			self.calmTaitDown();
		}
		else
		{
			if(Math.abs(myX-pissedX) > Math.abs(myY - pissedY))
			{
				if(myX < pissedX)
				{
					self.move(Direction.EAST);
				}
				else
				{
					self.move(Direction.WEST);
				}
			}
			else
			{
				if(myY < pissedY)
				{
					self.move(Direction.SOUTH);
				}
				else
				{
					self.move(Direction.NORTH);
				}
			}
		}
	}
}
